﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Bot.Domain
{
   public static class EnumerableExtensions
    {
        public static IEnumerable<T> DistinctBy<T,TKey>(this IEnumerable<T> source, Func<T,TKey> keySelector)
        {
            HashSet<TKey> seenKeys = new HashSet<TKey>();
            foreach(T element in source)
            {
                if (seenKeys.Add(keySelector(element)))
                {
                    yield return element;
                }
            }
        }
    }
}
